package com.cci.kangdao.ecjv.service.impl;

import com.cci.kangdao.dao.ECJVGraphicInformationTMapper;
import com.cci.kangdao.dao.model.ECJVGraphicInformationT;
import com.cci.kangdao.ecjv.service.ECJVGraphicInformationService;
import com.cci.kangdao.service.PropertiesUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author yinguili
 * @version 1.0
 * @description: TODO
 * @date 2022/8/29 10:45
 */
@Service("ECJVGraphicInformationService")
public class ECJVGraphicInformationServiceImpl implements ECJVGraphicInformationService {

    private Logger log = Logger.getLogger(this.getClass().getName());
    @Resource
    private PropertiesUtils propertiesUtils;

    @Resource
    private ECJVGraphicInformationTMapper ecjvGraphicInformationTMapper;

    @Override
    public PageInfo getGraphicInformation(Map<String, Object> map) {
        try {
            int page = 1;
            if (map.get("page") != null) {
                page = MapUtils.getInteger(map, "page", 1);
            }
            int pageSize = 10;
            if (map.get("pageSize") != null) {
                pageSize = Integer.parseInt(map.get("pageSize").toString());
            } else {
                pageSize = Integer.parseInt(this.propertiesUtils.getPropertiesValue("pageSize"));
            }
            PageHelper.startPage(page, pageSize);
            List<ECJVGraphicInformationT> ecjvInformationList = ecjvGraphicInformationTMapper.getEcjvInformationList(map);
            PageInfo pagination = new PageInfo(ecjvInformationList);
            return pagination;
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return null;
    }
}
